package net.lzzy.twocarsort;

import org.apache.spark.sql.AnalysisException;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.api.java.UDF1;
import org.apache.spark.sql.types.DataTypes;

public class StudentPhoneThicken {
    public static void main(String[] args) throws Exception {
        SparkSession ss = SparkSession.builder()
                .appName(StudentPhoneThicken.class.getName())
                .master("local")
                .getOrCreate();
        Dataset<Row> jsonData = ss.read().json("src/student.json");
        jsonData.createTempView("Student");

        ss.udf().register("thicken",
                (UDF1<Long, String>) s -> String.valueOf(s).substring(0, 3) + "****" + String.valueOf(s).substring(3, 7)
        ,DataTypes.StringType);

//        jsonData.show();
        ss.sql("select age,institute,name,thicken(phone) as `phone`,sex from Student").show((int) jsonData.count());
    }
}
